#ifndef _AOC_H__
#define _AOC_H__


template<class T>
	inline T Max(const T A, const T B)
	{
		return ( A >= B ) ? A : B;
	}

template<class T>
	inline T Min(const T A, const T B)
	{
		return (A <= B) ? A : B;
	}

#ifndef SAFE_DELETE
#	define SAFE_DELETE(p)			{ if(p) { delete (p);		(p)=NULL; } }
#endif

#ifndef SAFE_DELETE_ARRAY
#	define SAFE_DELETE_ARRAY(p)		{ if(p) { delete[] (p);		(p)=NULL; } }
#endif

#define ARRAY_COUNT(Array) \
	(sizeof(Array)/sizeof((Array)[0]))

#define OFFSETOF(s,m) \
	(__int32)&(((s *)0)->m)

PWSTR Run(PCWSTR, PWSTR, PCSTR, PCWSTR, BOOL, BOOL, BOOL);
PWSTR _lstrdup(PCWSTR);
INT _lstricmp(PCWSTR, PCSTR);
PWSTR _cdecl Error(PCWSTR, ...);

///////////////////////////////////////////////////////////////////////////////////////

class cLIB
{
public:
	PUCHAR	pBase;
	ULONG	ImageBase;
	ULONG	ImageSize;

	cLIB(PCWSTR Path)
	{
		if(pBase = (PUCHAR)LoadLibraryEx(Path, 0, LOAD_IGNORE_CODE_AUTHZ_LEVEL|DONT_RESOLVE_DLL_REFERENCES))
		{
			PIMAGE_NT_HEADERS NtHeaders = (PIMAGE_NT_HEADERS)(pBase + ((PIMAGE_DOS_HEADER)pBase)->e_lfanew);
			ImageBase = NtHeaders->OptionalHeader.ImageBase;
			ImageSize = NtHeaders->OptionalHeader.SizeOfImage;
		}
	}
	~cLIB()
	{
		FreeLibrary((HINSTANCE)pBase);
	}
};

///////////////////////////////////////////////////////////////////////////////////////


#endif